home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-04-04 | 2.8 KB | 90 lines | [TEXT/KAHL] |
- /********************************************************* DEFINITION
- DATE: 9/17/93
- AUTHOR: Eric R. Rosé
-
- CLASS: CPPWatchWriteTasks
-
- SUPERCLASS: CPeriodicTask
-
- This C++ class waits until there are no write tasks in the
- queue it belongs to and then disposes of the memory it is
- started up with.
- Q: What could you possibly use this for?
- A: When you spawn a write task, it has to be assured that the
- data it is writing out won't get cleared. Normally you could
- tell it that it has ownership of the data and let it dispose
- of it when it is done. However, if you spawn many write tasks,
- all with the same data, you have no guarantee the one you gave
- ownership of the data to will complete last, or, indeed, at all.
- To solve this, do not give any of the write tasks ownership of
- the data, then spawn a CWatchWriteMemTask and give it the
- responsibility of disposing of the memory after all of the write
- tasks have completed.
-
- ********************************************************************/
-
- #include "CPPWatchWriteTask.h"
- #include <CPPTaskManager.h>
- #include <MemoryTools.h>
-
- /*-----------------------------------------------------------------*/
- /*------------------------ PUBLIC METHODS -------------------------*/
- /*-----------------------------------------------------------------*/
-
- CPPWatchWriteTasks::CPPWatchWriteTasks (CPPTaskManager *TaskManager,
- long minPeriod) :
- CPPPeriodicTask (TaskManager, minPeriod, TRUE)
- {
- this->dataToWatch = NULL;
- }
-
- /*-----------------------------------------------------------------*/
-
- CPPWatchWriteTasks::~CPPWatchWriteTasks (void)
- {
- }
-
- /*-----------------------------------------------------------------*/
-
- char *CPPWatchWriteTasks::ClassName (void)
- {
- return "CPPWatchWriteTasks";
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPWatchWriteTasks::StartWatchTask (Ptr Data)
- {
- if (!this->hasCompleted)
- return;
-
- // save the pointer we are responsible for
- this->dataToWatch = Data;
-
- // now add the task to the periodic task manager queue
- this->hasCompleted = FALSE;
- this->ourManager->AddPeriodicTask(this);
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPWatchWriteTasks::DoPeriodicAction (void)
- // Call our manager's "HowManyTasksOfType" routine to count */
- /* the number of 'write' tasks in the queue; if there aren't */
- /* any, we should signal completion */
- {
- // call the inherited method to update frequency count
- CPPPeriodicTask::DoPeriodicAction();
-
- if (this->ourManager->HowManyTasksOfType("CPPWriteTask") <= 0)
- this->hasCompleted = TRUE;
- }
-
- /*-----------------------------------------------------------------*/
-
- void CPPWatchWriteTasks::DoCompletedAction (void)
- {
- CPPPeriodicTask::DoCompletedAction();
- NukePtr(this->dataToWatch);
- }
-